package com.freecloud.javabasics.thread.state;

import java.util.concurrent.TimeUnit;

/**
 * 线程状态DEMO可以通过
 * jps & jstack命令查看线程状态
 * @Author: maomao
 * @Date: 2020-01-21 16:27
 */
public class ThreadStatusDemo {

    public static void main(String[] args) {

        new Thread(() -> {
            while (true){
                try {
                    TimeUnit.SECONDS.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"Time_Waiting_Thread").start();


        new Thread(() -> {
            while (true){
                synchronized (ThreadStatusDemo.class){
                    try{
                        ThreadStatusDemo.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        },"Wating_Thread").start();

        //Blocked
        new Thread(new BlockedDemo(),"block01_thread").start();
        new Thread(new BlockedDemo(),"block02_thread").start();
    }


    static class BlockedDemo extends Thread{
        @Override
        public void run() {
            synchronized (BlockedDemo.class){
                while (true){
                    try {
                        TimeUnit.SECONDS.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
